<?php namespace Admin\Controller; 

use Hdphp\Controller\Controller;

//后台登录控制器
class loginController extends Controller{
	private $model;
	//框架自定义构造函数
	public function __init(){
	    //实例化后台登录表
	    $this->model = new \Common\Model\admin_user;
	}
    //默认
    public function index(){
    	//3.用户提交
    	if(IS_POST){
	    	//1.接收提交的账号密码
		    $username = Q('post.username');
			$password = Q('post.password','','md5');
//			//2.获得数据库的用户密码
			$data = $this->model->where("username='{$username}'")->get();
			//判断账号密码是否正确
			if($data[0]['username'] != $username || $data[0]['password'] != $password)	View::error('账号密码不正确');
			$_SESSION['uid'] = $data[0]['uid'];
			$_SESSION['username'] = $data[0]['username'];
			View::success('登陆成功',U('Index/index'));
		}
    	//载入模板
       View::make();
    }
}
